﻿using System;
using DBServer.Selenium.Extenium.Exception;
using DBServer.Selenium.Extenium.IFixture;
using Selenium;

namespace DBServer.Selenium.Extenium.Fixtures
{
    public class RowFixture : GridFixture
    {
        private readonly ISelenium _driver;
        private readonly string _name;
        private readonly int _index;

        public ICheckBox CheckBoxAtColumn(int indexOfColumn)
        {
            return new CheckRowGridFixture(_driver, _name,_index, indexOfColumn);
        }

        public RowFixture(ISelenium driver, string name, int index)
            : base(driver, name)
        {
            _driver = driver;
            _name = name;
            _index = index;
        }

        public CellFixture CellAtColumn(int index)
        {
            if (index < 0 || index >= ColumnCount())
            {
                throw new ExteniumException("Cell out of range: row: " + _index + " column: " + index);
            }

            return new CellFixture(_driver, _name, _index, index);
        }

        public ImageCellFixture ImageCellAtColumn(int index)
        {
            if (index < 0 || index >= ColumnCount())
            {
                throw new ExteniumException("Cell out of range: row: " + _index + " column: " + index);
            }

            return new ImageCellFixture(_driver, _name, _index, index);
        }

        public RowFixture DoubleClick()
        {
            //select this row
            SafeExec(Path.Eval() + ".selModel.selectRow(" + _index + ");");
            //runs double click
            SafeExec(Path.Eval() + ".events.rowdblclick.fire(" + Path.Eval() + ");");
            return this;
        }


/*        public ICheckBox CheckRow(int indexOfColumnOfCheck)
        {
            SafeExec(Path.Eval() + ".store.data.items[" + _index + "].set('selecionado', true);");
            return this;
        }*/
    }
}